<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>员工激活</title>
  <!-- Bootstrap 5 CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <!-- jQuery -->
  <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
  <!-- Bootstrap 5 JS -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body class="bg-light">

  <div class="container d-flex justify-content-center align-items-center min-vh-100">
    <div class="card shadow p-4" style="max-width: 400px; width: 100%;">
      <h3 class="text-center mb-4">员工激活</h3>
      <form id="activateForm">
        <div class="mb-3">
          <label for="email" class="form-label">邮箱地址</label>
          <input type="email" class="form-control" id="email" name="email" placeholder="请输入邮箱" required>
        </div>
        <div class="mb-3">
          <label for="password" class="form-label">密码</label>
          <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码" required>
        </div>
        <div class="d-grid">
          <button type="submit" class="btn btn-primary" id="submit-btn">激活</button>
        </div>
      </form>
      <div id="result" class="mt-3 text-center" style="display: none;"></div>
    </div>
  </div>

  <script>
    $('#submit-btn').on("click", function(event) {
      event.preventDefault();

      let email = $("#email").val();
      let password = $("#password").val();
      let emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

      if (!emailRegex.test(email)) {
        alert("邮箱格式错误");
        return;
      }
      if (password.length < 6) {
        alert("密码长度不能小于6");
        return;
      }

      $.post("/api/staff/active/", { email, password }, function (result) {
        if (result.code === 200) {
          alert("激活成功");
          window.location.href = "/";
        } else {
          alert(result.msg);
        }
      });
    });
  </script>
</body>
</html>
